﻿@model FCNS.ERP.Models.ErpStoreOrder

@{
    ViewBag.Title = ViewData["Flag"];
    Layout = "~/Views/Jxc/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>
@{int flag = (int)ViewData["Flag"];}

@Styles.Render("~/Content/dataTableCss")
@Scripts.Render("~/bundles/dataTableJs")

@using (Html.BeginForm())
{

    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        @Html.Hidden("Flag", flag)
        @Html.HiddenFor(model => model.StoreFlag)
        <input id="_OrderType" type="hidden" value="c" />
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.StoreId, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.DropDownList("StoreId", ViewData["Store"] as SelectList, htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.StoreId, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.DateTimeStart, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.EditorFor(model => model.DateTimeStart, new { htmlAttributes = new { @class = "form-control", @onClick = "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" } })
                        @Html.ValidationMessageFor(model => model.DateTimeStart, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

            <div class="col-sm-4">

            </div>
        </div>

        <hr />
        <div class="form-inline">
            <input type="button" value="保存订单" id="SaveOrder" class="btn btn-success" />&nbsp;&nbsp;&nbsp;&nbsp;
            @if (flag == 2)
            {
                Html.Raw("&nbsp; &nbsp; &nbsp;");<input type="button" value="导入盘点文件" id="ImportFile" class="btn btn-warning" />
                <div style="display:none;">
                    <input type="file" id="getFile" accept=".txt" />
                </div>
            }
            else
            {
                <div class="form-group">
                    <input type="text" id="InputCode" class="form-control text-box single-line" />
                </div>
                Html.Raw("&nbsp; &nbsp; &nbsp;");
                <input type="button" value="加载" id="LoadProduct" class="btn btn-info" />
            }
        </div>

        <div id="tableDetail">
            <table class="table">
                <thead>
                    <tr>
                        <th>编码</th>
                        <th>条形码</th>
                        <th>名称</th>
                        <th>单位</th>
                        <th>库存价</th>
                        <th>数量</th>
                        <th>小计</th>
                        @if (flag == 2)
                        {
                            <th>盘点数量</th>
                        }
                        <th></th>
                    </tr>
                </thead>
                <tbody></tbody>
                <tfoot><tr><td style="text-align:center;" colspan="6">合计</td><td id="calcSum">0</td><td></td><td></td></tr></tfoot>
            </table>
        </div>
    </div>
}

<script src="~/WebExtend/My97DatePicker/WdatePicker.js"></script>
<script src="/Scripts/Erp/defineDataTable.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#StoreFlag").val($("#Flag").val());
         
       $("#tableDetail tbody").empty();

        if ($("#Flag").val() == 2) {
            //填充要盘点的商品
            $("#tableDetail tbody").html("@Html.Raw(ViewData["AllProduct"])")
        }

        $("#ImportFile").click(function () {
            $("#getFile").click();
        });

        $(".btn-success").click(function () {
            var p = FormatProductList(); 
            if (p == "") {
                alert("商品列表不能为空");
            } 
            else {
                $("form").attr("action", "/Jxc/StoreOrderNew?productList=" + p).submit();
            }
        });
    });
</script>
